# 匿名函数
from functools import reduce


def fun(x, y):
    return x + y


a = lambda x, y: x + y
print(a(5, 6))


def f(x):
    return x ** 2


# map函数，主要传入两个值，一个是函数，第二个是参数，做映射用的
list1 = [1, 2, 3, 4, 5]
list2 = map(f, list1)
print(list(list2))
result = map(lambda x: x ** 2, list1)
print(list(result))

# reduce函数  累积
result = reduce(lambda x, y: x + y, list1)
print(result)

# filter 过滤
list2 = filter(lambda x: x % 2 == 0, list1)
print(list(list2))

a = [1, 2, 3, 4, 5, 6, 7, 8, 0, 10, 20, 30, 0, 1234]

list2 = filter(lambda x: x != 0, a)
print(list(list2))

list3 = [5, 4, 3, 1, 2]
list4 = sorted(list3)
print(list4)
